function loadImg(src) {
  const p = new Promise(
      (resolve, reject) => {
          const img = document.createElement('img')
          img.onload = () => {
              resolve(img)
          }
          img.onerror = () => {
              const err = new Error(`图片加载失败 ${src}`)
              reject(err)
          }
          img.src = src
      }
  )
  return p
}


const src1 = 'https://www.imooc.com/static/img/index/logo2020.png'
const src2 = 'http://img1.sycdn.imooc.com/5a9fc8070001a82402060220-160-160.jpg'

async function loadImg1() {
  const img1 = await loadImg(src1)
  return img1
}

async function loadImg2() {
  const img2 = await loadImg(src2)
  return img2
}

!(async function() {
  const img1 = await loadImg1(src1)
  console.log(img1.height, img1.width)

  const img2 = await loadImg2(src1)
  console.log(img2.height, img2.width)
})()